﻿using System;
using System.Runtime.InteropServices.ComTypes;

namespace Tsanie.ShellExt.Definitions
{
    /// <summary>
    /// IPersistFile 基础实现类
    /// </summary>
    public abstract class PersistFileBase : IPersistFile
    {
        const int E_NOTIMPL = unchecked((int)0x80004001);
        string m_FileName;
        string m_Ext;

        /// <summary>
        /// 获取文件名
        /// </summary>
        public string Filename { get { return m_FileName; } }

        /// <summary>
        /// 获取扩展名
        /// </summary>
        public string Ext { get { return m_Ext; } }

        void IPersistFile.GetClassID(out Guid pClassID) { pClassID = Guid.Empty; }
        void IPersistFile.GetCurFile(out string ppszFileName) { ppszFileName = null; }
        int IPersistFile.IsDirty() { return E_NOTIMPL; }
        void IPersistFile.Load(string pszFileName, int dwMode)
        {
            m_FileName = pszFileName;
            if (m_FileName != null)
            {
                int index = m_FileName.LastIndexOf('.');
                if (index > 0)
                {
                    m_Ext = m_FileName.Substring(index).ToLower();
                }
            }
        }
        void IPersistFile.Save(string pszFileName, bool fRemember) { }
        void IPersistFile.SaveCompleted(string pszFileName) { }
    }
}
